package com.next

class Component
{
    String name
    Boolean active = true

    ComponentType type

    String script

    Date createdDate = new Date()
    Date modifiedDate = new Date()

    User createBy
    User modifyBy

    static constraints = {
        name maxSize: 64, unqiue: true
        script type: "text"
    }

    static mapping = {
        sort 'name'
        cache true
    }

    def springSecurityService

    def beforeUpdate()
    {
        modifiedDate = new Date()

        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }

    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        createBy = User.findByUsername(username)
        modifyBy = User.findByUsername(username)
    }
}
